﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace UcAsp.Net.Extract
{
    public partial class CustomControl1 : Control
    {
        private Bitmap bitmapon;
        private Bitmap bitmapleve;
        public CustomControl1()
        {
            InitializeComponent();
            SetStyle(ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint
                    | ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
           // bitmapon = new Bitmap(Properties.Resources.button);
           //bitmapleve = new Bitmap(Properties.Resources.d);
        }
        #region 重写属性

        protected override CreateParams CreateParams
        {
            get
            {
                var result = base.CreateParams;
                result.ExStyle |= 0x00000020;
                return result;
            }
        }
        
        #endregion
        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);

           // Graphics g = Graphics.FromImage(bitmapleve);
           // g.SmoothingMode = SmoothingMode.HighQuality;


            
           //pe.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
           //// pe.Graphics.FillPie(new SolidBrush(Color.Blue), 0, 0, 30, 30, 0, 270);
           //pe.Graphics.DrawImage(bitmapon, 0, 0);
           // SizeF size=pe.Graphics.MeasureString("sadfasfdasfdsfasdf",new Font(new FontFamily("宋体"),24));
           // float l=(this.Width-size.Width)/2;
           // float t=(this.Height-size.Height)/2;
           // Brush b = new SolidBrush(Color.White);
           // pe.Graphics.DrawString("sadfasfdasfdsfasdf", new Font(new FontFamily("宋体"), 24), b, l, t);
           // pe.Graphics.Dispose();
          
        }

        protected override void OnClick(EventArgs e)
        {
            base.OnClick(e);
        }
        protected override void OnMouseHover(EventArgs e)
        {
            base.OnMouseHover(e);
            Graphics g = this.CreateGraphics();
           
           // bitmap.MakeTransparent(Color.Transparent);
            g.DrawImage(bitmapon, 0, 0);
            SizeF size = g.MeasureString(this.Text, new Font(new FontFamily("宋体"), 24));
            float l = (this.Width - size.Width) / 2;
            float t = (this.Height - size.Height) / 2;
            Brush b = new SolidBrush(Color.White);
            g.DrawString(this.Text, new Font(new FontFamily("宋体"), 24), b, l, t);
            g.Dispose();
        }
        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);
            //Graphics g = this.CreateGraphics();

            //g.DrawImage(bitmapon, 0, 0);
            //SizeF size = g.MeasureString(this.Text, new Font(new FontFamily("宋体"), 24));
            //float l = (this.Width - size.Width) / 2;
            //float t = (this.Height - size.Height) / 2;
            //Brush b = new SolidBrush(Color.White);
            //g.DrawString(this.Text, new Font(new FontFamily("宋体"), 24), b, l, t);
            //g.Dispose();
        }
        protected override void OnGotFocus(EventArgs e)
        {
            base.OnGotFocus(e);
        }
    }
}
